#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "menu.h"

SDL_Surface *ecran = NULL;


int main(int argc, char *argv[])
{

    SDL_Init(SDL_INIT_VIDEO);
    ecran=SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
    SDL_WM_SetCaption("PAC MAN ESPRIT 2P3", NULL);
    SDL_WM_SetIcon(SDL_LoadBMP("icone.bmp"), NULL);
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 255));
    SDL_Flip(ecran);

    menu(ecran);
    SDL_Quit();

    return EXIT_SUCCESS;
    SDL_FreeSurface(ecran);
}

void menu(SDL_Surface *ecran)

{
    SDL_Rect position,position_menu;
    SDL_Event event;
    int m;
    int continuer = 1;
    SDL_Surface* menu_bmp = SDL_LoadBMP("menu.bmp");
    SDL_Surface* menu0_bmp = SDL_LoadBMP("menu0.bmp");
    SDL_Surface* menu1_bmp = SDL_LoadBMP("menu1.bmp");
    SDL_Surface* menu2_bmp = SDL_LoadBMP("menu2.bmp");
    SDL_Surface* menu3_bmp = SDL_LoadBMP("menu3.bmp");

    position_menu.x = (ecran->w - menu_bmp->w) / 2;
    position_menu.y = (ecran->h - menu_bmp->h) / 2;
    SDL_BlitSurface(menu_bmp, NULL, ecran, &position_menu);
    SDL_Flip(ecran);


    m=0;
    while (continuer)
    {


        //menu logic
        while(SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                continuer = 0;
            case SDL_KEYDOWN:
            {
                if (event.key.keysym.sym == SDLK_ESCAPE)
                    continuer=0;
                if (event.key.keysym.sym == SDLK_BACKSPACE)
                    continuer=0;
                if (event.key.keysym.sym == SDLK_DOWN)
                    m++;

                break;
            }

            }




        }

          //partie 2 : affichage des entites

        SDL_BlitSurface(menu_bmp, NULL, ecran, &position_menu);
        m=m%4;

        if(m == 0)
            SDL_BlitSurface(menu0_bmp, NULL, ecran, &position_menu);
        if(m == 1)
            SDL_BlitSurface(menu1_bmp, NULL, ecran, &position_menu);
        if(m == 2)
            SDL_BlitSurface(menu2_bmp, NULL, ecran, &position_menu);
        if(m == 3)
            SDL_BlitSurface(menu3_bmp, NULL, ecran, &position_menu);



        SDL_Flip(ecran); //action  3 et 4 dans game loop
    }
}





